package com.example.mam.web;


import com.example.mam.constant.Constant;
import com.example.mam.dto.BaseResult;
import com.example.mam.dto.TableResult;
import com.example.mam.dto.TreeNode;
import com.example.mam.service.Mt5GroupsService;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/groups")
public class Mt5GroupsController {

    @Resource
    private Mt5GroupsService mt5GroupsService;

    @GetMapping("/queryAllGroupsName")
    public BaseResult<Object> queryAllGroupsTree() {
        List<TreeNode> result = new ArrayList<>();
        TreeNode treeNode =  mt5GroupsService.selectAllGroupName();
        result.add(treeNode);
        System.out.println(treeNode);
        return new BaseResult<Object>(true, result);
    }


    @GetMapping("/queryAllMAMGroup")
    public BaseResult<Object> queryAllMAMGroup() {
        return new BaseResult<>(true, mt5GroupsService.selectAllMAMGroups());
    }


    /**
     * 查询MAM组的账号
     * @param groupId 用户组ID
     * @return
     */
    @GetMapping("/queryAccountByMAMGroup/{id}")
    public BaseResult<Object> queryAccountByMAMGroup(@PathVariable("id") Long groupId) {
        return new BaseResult<>(true, mt5GroupsService.selectAllAccountByGroups(groupId));
    }


    /**
     * 设置为MAM组
     *
     * @param groupId 用户组ID
     * @return
     */
    @GetMapping("/setMAMGroup/{id}")
    public BaseResult<Object> setMAMGroup(@PathVariable("id") Long groupId) {
        mt5GroupsService.setMAMGroup(groupId, Constant.IS_MAMIS_);
        return new BaseResult<>(true, null);
    }

    /**
     * 取消设置MAM组
     *
     * @param groupId 用户组ID
     * @return
     */
    @GetMapping("/cancelMAMGroup/{id}")
    public BaseResult<Object> cancelMAMGroup(@PathVariable("id") Long groupId) {
        mt5GroupsService.cancleMAMGroup(groupId, Constant.NOT_MAMIS_);
        return new BaseResult<>(true, null);
    }


    /**
     *
     * @param groupId
     * @return
     */
    @GetMapping("/queryGroupsByGroupId/{groupId}")
    public BaseResult<Object> queryGroupsByGroupId(@PathVariable("groupId")  String  groupId) {
        System.out.println(groupId);
        return new BaseResult<>(true, mt5GroupsService.selectGroupById(groupId));
    }



}
